import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('1.jpg')
height = img.shape[0]
width = img.shape[1]
new_img = np.zeros((height, width, 3),np.uint8)
for i in range(height):
    for j in range(width):
        for k in range(3):
            if img[i ,j][k] < 128:
                gray = 0
            else:
                gray =128
            new_img[i, j][k] = np.uint8(gray)
img_rgb = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
new_img_rgb = cv2.cvtColor(new_img,cv2.COLOR_BGR2RGB)
plt.figure(figsize=(10, 5))
plt.subplot(1,2,1)
plt.imshow(img_rgb)
plt.title('Original Image')
plt.axis('off')
plt.subplot(1,2,2)
plt.imshow(new_img_rgb)
plt.title('Quantized Image')
plt.axis('off')
plt.show()